package com.wh.service.stock;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wh.mapper.stock.StockMapper;
import com.wh.pojo.Stock;
import com.wh.vo.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

@Service
public class StockServiceImpl implements StockService{

    @Autowired
    private StockMapper stockMapper;


    @Override
    public PageResult getStockList(PageResult pageResult) {
        Page<Stock> page = new Page<>(pageResult.getPageNum(),pageResult.getPageSize());
        boolean flag = StringUtils.hasLength(pageResult.getQuery());
        QueryWrapper<Stock> queryWrapper = new QueryWrapper<>();
        queryWrapper.like(flag,"product_name",pageResult.getQuery());
        page = stockMapper.selectPage(page,queryWrapper);
        pageResult.setTotal((long) page.getRecords().size()).setRows(page.getRecords());
        return pageResult;
    }
}
